package view;

import java.rmi.AlreadyBoundException;
import java.rmi.registry.Registry;
import java.rmi.registry.LocateRegistry;
import java.rmi.server.UnicastRemoteObject;
import java.util.Scanner;


import data.Player;
import controller.ServiceGame;
import controller.ServicePlayer;

public class Client {
	
	public static void main(String args[]) throws Exception 
	{
		Registry registry;
		ServicePlayer servicePlayer;
		ServiceGame serviceGame;
		
		registry = LocateRegistry.getRegistry("localhost", 3000);
		servicePlayer = (ServicePlayer) registry.lookup("ServicePlayer");
		serviceGame =(ServiceGame) registry.lookup("ServicePlayer");
		
		Player p = new Player();
		
		try {
			User stubUser = (User) UnicastRemoteObject.exportObject(p,0);
			registry.bind("User", stubUser);
		} catch(AlreadyBoundException e) {}
		
		Scanner sc = new Scanner(System.in);
		System.out.println("Veuillez saisir votre login :");
		String login = sc.nextLine();
		p=servicePlayer.connexion(login);
		
		System.out.println("Selectionnez votre action:");
		System.out.println("0: rejoindre une partie");
		System.out.println("1: creer partie");
		System.out.println("3: consulter score");
		System.out.println("4: classement");
		System.out.println("5: deconnexion");
		String response= sc.nextLine();
		int integerResp= Integer.valueOf(response);
		while (integerResp<0 || integerResp>5){
			System.out.println("mauvais choix");
			response= sc.nextLine();
			integerResp= Integer.valueOf(response);
		}
		
		switch (integerResp) {
		case 0:
			break;
		case 1:
			System.out.println("création de partie");
			System.out.println("combien de joueur? entre 2 et 5");
			response= sc.nextLine();
			integerResp= Integer.valueOf(response);
			while (integerResp<2 || integerResp>5){
				System.out.println("mauvais choix");
				response= sc.nextLine();
				integerResp= Integer.valueOf(response);
			}
			serviceGame.createGame(p,integerResp);
			fileAttente();
			break;
		case 2:
			break;
		case 3:
			break;
		case 4:
			break;
		case 5:
			servicePlayer.deconnexion(p);
			break;
		}
	}

	private static void fileAttente() {
	}
}

